package pyx.crazycards.game.managers;

import pyx.crazycards.game.cards.Card;
import pyx.crazycards.game.exception.CrazyCardServerException;

public class DataObjectParser {
	
	public static Card fromManager(pyx.crazycards.game.managers.Card card) {
		
		Card c = new Card();
		c.setName(card.getName());
		c.setCode(card.getCode());
		c.setSubId(card.getSubId());
		c.setDescription(card.getDescription());
		c.setType(card.getType());
		
		if (card.getAction() != null)
			c.setActionType(card.getAction().getType());
		
		c.setFlipped(card.getFlipped());
		c.setLocked(card.getLocked());
		c.setCost(card.getCost());
		c.setValue(card.getValue());
		
		return c;
	}
	
	public static pyx.crazycards.game.managers.Card toManager(Card card) throws CrazyCardServerException {
		pyx.crazycards.game.managers.Card c = null;
		if(card != null) {
			c = new pyx.crazycards.game.managers.Card();
			c.setCode(card.getCode());
			c.load();
			c.setSubId(card.getSubId());
			
			c.setFlipped(card.getFlipped());
			c.setLocked(card.getLocked());		
		}
		
		return c;
	}	
}
